import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class SolutionInterview16_21 {
    public int[] findSwapValues(int[] array1, int[] array2) {
        int a=Arrays.stream(array1).sum();
        int b=Arrays.stream(array2).sum();
        if ((a-b)%2==1 || (a-b)%2==-1){
            return new int[]{};
        }
        Set<Integer> set=new HashSet<>();
        for (int i : array1) {
            set.add(i);
        }
        for (int i : array2) {
            if (set.contains(i+(a-b)/2)){
                return new int[]{i+(a-b)/2,i};
            }
        }
        return new int[]{};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new SolutionInterview16_21().findSwapValues(new int[]{4, 1, 2, 1, 1, 2}, new int[]{3, 6, 3, 3})));
    }
}
